﻿@using SCMS.Resources
@model SCMS.UI.Models.ViewGRN
<div class="partialViewCard">
    <div class="partialViewCardHeader">
        <h3>
            @Resources_frank.Global_String_GRN: @Model.EntityGRN.RefNumber</h3>
    </div>
    @if (Model.CanApprove)
    {
        string linkText = null;
        string actionName = null;
        if (Model.EntityGRN.IsSubmitted && !Model.EntityGRN.Verified)
        {
            linkText = Resources_frank.GoodsReceivedNote_ViewGRNDetails_VerifyGRN;
            actionName = "VerifyGRN";
        }
        if (linkText != null)
        {
            <center>
                @Ajax.ActionLink(linkText, actionName, "RequestReview", new { id = "" }, new AjaxOptions
                {
                    OnBegin = "ShowDialogueOR('" + linkText + ": " + Model.EntityGRN.RefNumber + "')",
                    UpdateTargetId = "popup-page",
                    LoadingElementId = "popup-loading",
                    Url = Url.Action(actionName + "/" + Model.EntityGRN.Id, "RequestReview"),
                    OnSuccess = "CenterPopup"
                }) 
            </center>
        }
    }
    else
    {
        <br />
    }
    <table width="98%" align="center" cellspacing="0" cellpadding="0" border="1" class="cardTable">
        <tr class="gridheader">
            <th align="center" colspan="2">
                @Resources_frank.GoodsReceivedNote_VerifyGRN_VendorInformation.ToUpper()
            </th>
            <th align="center" colspan="2">
                @Resources_frank.GoodsReceivedNote_VerifyGRN_InternalInformation.ToUpper()
            </th>
        </tr>
        <tr class="gridodd">
            <td style="width: 15%;">
                <strong>@Resources_frank.Global_String_Supplier.ToUpper():</strong>
            </td>
            <td style="width: 34%;">
                @Model.EntityGRN.Supplier.Name
            </td>
            <td style="width: 15%;">
                <strong>@Resources_frank.Global_String_Location.ToUpper():</strong>
            </td>
            <td style="width: 34%;">
                @Model.EntityGRN.CountrySubOffice.Location.Name
            </td>
        </tr>
        <tr class="gridodd">
            <td>
                <strong>@Resources_frank.GoodsReceivedNote_DownloadTemplate_DNNo:</strong>
            </td>
            <td>
                @Model.EntityGRN.DnNumber
            </td>
            <td>
                <strong>@Resources_frank.Global_String_Office.ToUpper():</strong>
            </td>
            <td>
                @Model.EntityGRN.CountrySubOffice.Name
            </td>
        </tr>
        <tr class="gridodd">
            <td>
                <strong>@Resources_frank.GoodsReceivedNote_VerifyGRN_DrcDdgORNo:</strong>
            </td>
            <td>
                @if (Model.EntityGRN.GoodsReceivedNoteItems.Count > 0)
                {
                    @Model.EntityGRN.GoodsReceivedNoteItems.ToList()[0].PurchaseOrderItem.PurchaseOrder.OrderRequest.RefNumber
                }
            </td>
            <td>
                <strong>@Resources_frank.GoodsReceivedNote_VerifyGRN_DrcDdgPONo:</strong>
            </td>
            <td>
                @if (Model.EntityGRN.GoodsReceivedNoteItems.Count > 0)
                {
                    @Model.EntityGRN.GoodsReceivedNoteItems.ToList()[0].PurchaseOrderItem.PurchaseOrder.RefNumber
                }
            </td>
        </tr>
    </table>
    <br />
    <table width="98%" align="center" cellspacing="0" cellpadding="0" border="1" class="cardTable">
        <tr class="gridheader">
            <th>
            </th>
            <th>
                @Resources_frank.GoodsReceivedNote_VerifyGRN_GoodsDescription
            </th>
            <th>
                @Resources_morgan.Global_String_UnitOfMeasure
            </th>
            <th>
                @Resources_frank.Global_String_QtyOrdered
            </th>
            <th>
                @Resources_frank.Global_String_QtyDelivered
            </th>
            <th>
                @Resources_morgan.Global_String_QtyDamaged
            </th>
            <th>
                @Resources_morgan.Global_String_Comments
            </th>
        </tr>
        @{int count = 0;}
        @foreach (var item in Model.EntityGRN.GoodsReceivedNoteItems)
        {
            count = count + 1;
            <tr class="gridodd">
                <td style="width: 5%; text-align: left;">
                    @count
                </td>
                <td style="width: 21%; text-align: left;">
                    @item.PurchaseOrderItem.OrderRequestItem.Item.Name
                </td>
                <td style="width: 10%; text-align: left;">
                    @item.PurchaseOrderItem.OrderRequestItem.Item.UnitOfMeasure.Code
                </td>
                <td style="width: 14%; text-align: right;">
                    @item.PurchaseOrderItem.Quantity.ToString("##,##0.00")
                </td>
                <td style="width: 14%; text-align: right;">
                    @item.QuantityDelivered.ToString("##,##0.00")
                </td>
                <td style="width: 14%; text-align: right;">
                    @item.QuantityDamaged.ToString("##,##0.00")
                </td>
                <td style="width: 20%; text-align: left;">
                    @item.Comments
                </td>
            </tr>
        }
        <tr>
            <td class="gridheader" colspan="2">
                <strong>@Resources_frank.Global_String_AdditionalRemarks:</strong>
            </td>
            <td align="left" colspan="5">
                @Model.EntityGRN.Remarks
            </td>
        </tr>
    </table>

   <br />
        <table width="98%" align="center" cellspacing="0" cellpadding="0" border="1" class="cardTable">
            <tr>
                <td rowspan="2" style="width: 10%;" class="gridheader">
                    <strong>@Resources_frank.GoodsReceivedNote_VerifyGRN_TransporterSupplier</strong>
                </td>
                <td style="width: 16%;" class="gridheader">
                    @Resources_frank.Global_String_DeliveredByName:
                </td>
                <td style="width: 20%;">
                    @Model.EntityGRN.DeliveredBy
                </td>
                <td style="width: 10%;" class="gridheader">
                    @Resources_frank.Global_String_Company:
                </td>
                <td style="width: 20%;">
                    @Model.EntityGRN.DeliveryCompany
                </td>
                <td style="width: 8%;" class="gridheader">
                    @Resources_frank.FleetManager_LoadNewFleetDetail_PlateNo:
                </td>
                <td style="width: 20%;">
                    @Model.EntityGRN.VehicleRegNumber
                </td>
            </tr>
            <tr>
                <td class="gridheader">
                    @Resources_frank.FleetManager_LoadFleetDetails_DriverLicenseNo:
                </td>
                <td>
                    @Model.EntityGRN.DriverLicenseNumber
                </td>
                <td class="gridheader">
                    @Resources_frank.Global_String_Signature:
                </td>
                <td>
                </td>
                <td class="gridheader">
                    @Resources_frank.Global_String_Date:
                </td>
                <td>
                    @Model.EntityGRN.DeliverDate.Value.ToString("dd/MM/yyyy")
                </td>
            </tr>
            <tr>
                <td colspan="7">
                    &nbsp;
                </td>
            </tr>
            <tr>
                <td rowspan="2" class="gridheader">
                    <strong>@Resources_morgan.Global_String_DRCDDG</strong>
                </td>
                <td class="gridheader" rowspan="2" valign="top">
                    @Resources_frank.Global_String_ReceivedByName:
                </td>
                <td>
                    @Model.ReceivedBy.StaffName
                </td>
                <td class="gridheader">
                    @Resources_frank.Global_String_Title:
                </td>
                <td>
                    @Model.ReceivedBy.Designation
                </td>                
                <td class="gridheader" rowspan="2" valign="top">
                    @Resources_frank.Global_String_Date:
                </td>
                <td>
                    @Model.EntityGRN.DeliverDate.Value.ToString("dd/MM/yyyy")
                </td>
            </tr>
            <tr>
                <td>
                </td>
                <td class="gridheader">
                    @Resources_frank.Global_String_Signature:
                </td>
                <td>
                    @if (Model.EntityGRN.Staff1 != null && Model.EntityGRN.Staff1.Person.SignatureImage != null)
                    { 
                        <img src="@Url.Action("Photo", "Person", new { id = Model.EntityGRN.Staff1.Person.Id, area = "" })" alt="" style="max-width: 100px;" />
                    }
                </td>
                <td>&nbsp;</td>
            </tr>
            <tr>
                <td colspan="7">
                    &nbsp;
                </td>
            </tr>
            <tr>
                <td rowspan="2" class="gridheader">
                    <strong>@Resources_morgan.Global_String_DRCDDG</strong>
                </td>
                <td class="gridheader" rowspan="2" valign="top">
                    @Resources_frank.GoodsReceivedNote_ViewGRNDetails_ReceptionApproved:
                </td>
                <td>
                    @if (Model.EntityGRN.Staff != null)
                    {
                        @Model.EntityGRN.Staff.Person.FirstName
                        @Html.Raw("&nbsp;")
                        @Model.EntityGRN.Staff.Person.OtherNames
                    }
                </td>
                <td class="gridheader">
                    @Resources_frank.Global_String_Title:
                </td>
                <td>
                    @if (Model.EntityGRN.Staff != null)
                    {
                        @Model.EntityGRN.Staff.Designation.Name
                    }
                </td>                
                <td class="gridheader" rowspan="2" valign="top">
                    @Resources_frank.Global_String_Date:
                </td>
                <td>
                    @if (Model.EntityGRN.Staff != null)
                    {
                        @Model.EntityGRN.ApprovedOn.Value.ToString("dd/MM/yyyy h:mm tt")
                    }
                </td>
            </tr>
            <tr>
                <td>
                </td>
                <td class="gridheader">
                    @Resources_frank.Global_String_Signature:
                </td>
                <td>
                    @if (Model.EntityGRN.Staff != null && Model.EntityGRN.Staff.Person.SignatureImage != null)
                    { 
                        <img src="@Url.Action("Photo", "Person", new { id = Model.EntityGRN.Staff.Person.Id, area = "" })" alt="" style="max-width: 100px;" />
                    }
                </td>
                <td>&nbsp;</td>
            </tr>
        </table>
    <hr />
    <a class="btn btn-primary" target="_blank" href="/Reports/GoodsReceived/Index/@Model.EntityGRN.Id"  style="margin-left: 48%; margin-bottom: 2%;">
        @Resources_frank.Budget_ViewBudget_DownloadPdf
    </a>
   
</div>
<br />
<p>
    @Ajax.ActionLink(Resources_frank.Global_String_BackToList, "Index", new { id = "ViewGRNs" }, new AjaxOptions
    {
        UpdateTargetId = "ContentDiv",
        LoadingElementId = "loading",
        Url = Url.Action("ViewGRNs"),
        OnSuccess = "if (document.getElementById('table') != null) {initSorter();sorter.size(20);}"
    })    
</p>
